import java.util.ArrayList;
import java.util.HashSet;
import java.util.Hashtable;


public class ErrorHandler extends Hashtable<Integer, String> {
	private final String newline = System.getProperty("line.separator");
	private ArrayList<Integer> usedErrors = new ArrayList<Integer>();
	private int errorcount = 0;
	
	public ErrorHandler(){
		this.put(1, "PROGRAM NAME IS INVALID, MUST BE 2-32 CHARACTERS AND NUMBERS LONG AND MUST BEGIN WITH A LETTER");
		this.put(2, "LOAD PAGE IS INVALID, MUST BE IN RANGE OF 0-3");
		this.put(3, "LOAD PAGE CONTAINS INVALID HEXADECIMAL SYNTAX");
		this.put(4, "LOAD ADDRESS IS INVALID, MUST BE IN RANGE OF 0-4095");
		this.put(5, "LOAD ADDRESS CONTAINS INVALID HEXADECIMAL SYNTAX");
		this.put(6, "LOAD ADDRESS LENGTH MUST BE 6 HEX DIGITS IN LENGTH");
		this.put(7, "INVALID MODULE LENGTH, MUST BE IN RANGE 0-16383");
		this.put(8, "HEADER RECORDS MODULE LENGTH VALUE MUST BE 4 HEX DIGITS IN LENGTH");
		this.put(9, "HEADER RECORDS MODULE LENGTH VALUE CONTAINS INVALID HEXADECIMAL SYNTAX");
		this.put(10, "HEADER RECORDS EXECUTION START ADDRESS EXCEEDS THE PROGRAM LENGTH");
		this.put(11, "HEADER RECORDS EXECUTION START ADDRESS MUST BE 4 HEX DIGITS IN LENGTH");
		this.put(12, "EXECUTION START ADDRESS CONTAINS INVALID HEXADECIMAL SYNTAX");
		this.put(13, "PROGRAM NAMES MUST MATCH IN THE HEADER RECORD OF AN OBJECT FILE");
		this.put(14, "LOAD FILE SHOULD HAVE BEEN PRODUCED BY A FICKELL LINKER");
		this.put(15, "HEADER RECORDS MUST CONTAIN EXACTLY 11 FIELDS");
		this.put(16, "PROGRAM ASSIGNED PAGE VALUE IS INVALID, MUST BE IN RANGE OF 0-3");
		this.put(17, "PROGRAM ASSIGNED PAGE VALUE CONTAINS INVALID HEXADECIMAL SYNTAX");
		this.put(18, "PROGRAM ASSIGNED PAGE AND LOCATION COMBINED MUST BE 6 HEX DIGITS IN LENGTH");
		this.put(19, "PROGRAM ASSIGNED LOCATION VALUE IS INVALID, MUST BE IN RANGE OF 0-16383");
		this.put(20, "PROGRAM ASSIGNED LOCATION VALUE CONTAINS INVALID HEXADECIMAL SYNTAX");
		this.put(21, "INSTRUCTION/DATA WORD CONTAINS INVALID HEXADECIMAL SYNTAX");
		this.put(22, "INSTRUCTION/DATA WORD MUST BE 8 HEX DIGITS IN LENGTH");
		this.put(23, "TEXT RECORDS MUST CONTAIN EXACTLY 4 FIELDS");
		this.put(24, "THE VALUE OF TOTAL RECORDS IN THE END RECORD DOES NOT MATCH THE TOTAL RECORD COUNT");
		this.put(25, "TOTAL RECORDS HEX VALUE IN THE END RECORD MUST HAVE A LENGTH OF 4");
		this.put(26, "THE VALUE OF TOTAL RECORDS CONTAINS INVALID HEXADECIMAL SYNTAX");
		this.put(27, "THE VALUE OF TOTAL TEXT RECORDS IN THE END RECORD DOES NOT MATCH THE TEXT RECORD COUNT");
		this.put(28, "NUMBER OF TEXT RECORDS EXCEED THE MODULES LENGTH");
		this.put(29, "TOTAL TEXT RECORDS HEX VALUE IN THE END RECORD MUST HAVE A LENGTH OF 4");
		this.put(30, "THE VALUE OF TOTAL TEXT RECORDS CONTAINS INVALID HEXADECIMAL SYNTAX");
		this.put(31, "PROGRAM NAME IN THE END RECORD DOES NOT MATCH THE MODULES NAME");
		this.put(32, "END RECORDS MUST HAVE EXACTLY 6 FIELDS");
		this.put(33, "INVALID RECORD TYPE, MUST EITHER BE A HEADER (H), TEXT (T), OR END (E) RECORD");
		this.put(34, "OVERFLOW ERROR!");
		this.put(35, "INVALID INSTRUCTION!");
		this.put(36, "MEMORY IS OUT OF BOUNDS");


		this.put(18, "IT WORKS");
	}

	public ArrayList<Integer> getUsedErrors(){
		return usedErrors;
	}
	
	public int getErrorCount(){
		return errorcount;
	}
	
	public void clearUsedErrors(){
		usedErrors.clear();
	}
	
	public void clearAllErrors(){
		usedErrors.clear();
		errorcount = 0;
	}
	
	public String getError(int errorcode){
		return "ERROR " + errorcode + ": " + this.get(errorcode);
	}
}
